﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using CSequence;

namespace Sequence
{
    public partial class FrmReorder : Form
    {
        public FrmReorder()
        {
            InitializeComponent();
        }
        public bool bToSave = false;

        FileSequence m_oFileSequence;
        public FrmReorder(ref FileSequence oFileSequence)
        {
            InitializeComponent();
            m_oFileSequence = oFileSequence;
            foreach ( CStep oStep in oFileSequence.oSteps)
            {
                ListViewItem oListViewItem = listView1.Items.Add(oStep.sId);
                oListViewItem.SubItems[0].Text = oStep.sId;
                oListViewItem.SubItems.Add(oStep.sName);
            }
        }

        private void cmdUp_Click(object sender, EventArgs e)
        {
            if (listView1.SelectedItems.Count > 0)
            {
                int iSelected = listView1.SelectedItems[0].Index;
                if (iSelected > 0)
                {
                    string sSaveId = listView1.Items[iSelected - 1].SubItems[0].Text;
                    string sSaveName = listView1.Items[iSelected - 1].SubItems[1].Text;

                    listView1.Items[iSelected - 1].SubItems[0].Text = listView1.Items[iSelected].SubItems[0].Text;
                    listView1.Items[iSelected - 1].SubItems[1].Text = listView1.Items[iSelected].SubItems[1].Text;

                    listView1.Items[iSelected].SubItems[0].Text = sSaveId;
                    listView1.Items[iSelected].SubItems[1].Text = sSaveName;
                    listView1.Items[iSelected].Selected = false;
                    listView1.Items[iSelected - 1].Selected = true;
                }            
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            int i = 1;
            foreach (ListViewItem oItem in listView1.Items)
            {
                CStep oStep = m_oFileSequence.oSteps.Find(element => element.sName == oItem.SubItems[1].Text);
                oStep.sId = i.ToString();
                i++;
            }
            bToSave = true;
        }
    }
}
